package com.baiyang.app.ui.bookshelf;

import android.content.Context;

import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.alibaba.fastjson.JSONObject;
import com.baiyang.app.MyApp;
import com.baiyang.app.model.Article;
import com.baiyang.app.model.User;
import com.baiyang.app.tool.LoadDataScrollController;
import com.baiyang.app.tool.LogUtils;
import com.baiyang.app.tool.MyAdapter;
import com.baiyang.app.tool.net.SendMsgUtil;
import com.baiyang.app.tool.net.Urls;
import com.baiyang.app.ui.bookCity.BookCityService;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Response;

public class BookshelfService {

    private Context context;
    private BookshelfViewModel viewModel;

    private RecyclerView recyclerView;
    //下拉刷新
    private SwipeRefreshLayout mSwipeRefresh;
    private LoadDataScrollController mController;
    private MyAdapter<Article> myAdapter ;

    public BookshelfService(Context context,BookshelfViewModel viewModel){
        this.context = context;
        this.viewModel = viewModel;
    }

    /**
     * 关注
     */
    public void getFollowList(){
        JSONObject object = new JSONObject();
        User user = MyApp.getInstance().getUser();
        object.put("userId",user.getId());
        new SendMsgUtil(){
            @Override
            public void deal(Call call, Response response) throws IOException {
                if(response.code() == 200){
                    String str = response.body().string();
                    LogUtils.i("getFollowList",str);
                    viewModel.setFollowListResult(JSONObject.parseObject(str));
                }else{
                    LogUtils.i("getFollowList","code:" + response.code());
                }
            }
            @Override
            public void dealFailure(Call call, IOException e) throws IOException {
                LogUtils.i("getFollowList","IOException:" + e.getLocalizedMessage());
            }
        }.sendPost(Urls.BOOKSHELF.GET_FOLLOW_LIST,object);
    }

}
